<template>
  <view class="video-player-container">
    <view class="header">
      <view class="back-btn" @click="back">
        <image src="/static/ic_back_icon.png" mode="aspectFit" class="back-icon"></image>
      </view>
      <text class="title">视频播放</text>
      <view class="empty"></view>
    </view>
    
    <view class="video-content">
      <video 
        :src="videoSrc" 
        class="video"
        :controls="true"
        :autoplay="false"
        :loop="false"
        :muted="false"
        object-fit="contain"
        @error="videoError"
      ></video>
    </view>
    
    <view v-if="errorMessage" class="error-message">
      {{ errorMessage }}
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      videoSrc: '',
      errorMessage: ''
    }
  },
  onLoad(options) {
    // 获取传入的视频地址参数
    if (options.src) {
      this.videoSrc = decodeURIComponent(options.src)
    }
  },
  methods: {
    // 返回上一页
    back() {
      uni.navigateBack()
    },
    // 视频播放错误处理
    videoError(e) {
      console.error('视频播放错误:', e)
      this.errorMessage = '视频加载失败，请检查网络连接或视频地址'
    }
  }
}
</script>

<style scoped>
.video-player-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background-color: #000;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 88rpx;
  background-color: #000;
  padding: 0 30rpx;
}

.back-btn {
  width: 88rpx;
  height: 88rpx;
  display: flex;
  align-items: center;
  justify-content: center;
}

.back-icon {
  width: 44rpx;
  height: 44rpx;
}

.title {
  color: #fff;
  font-size: 36rpx;
  font-weight: 500;
}

.empty {
  width: 88rpx;
}

.video-content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #000;
  overflow: hidden;
}

.video {
  width: 100%;
  height: 100%;
}

.error-message {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #fff;
  font-size: 32rpx;
  background-color: rgba(0, 0, 0, 0.7);
  padding: 20rpx 40rpx;
  border-radius: 8rpx;
}
</style>